<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<body>

<?php

//连接数据库
try {
    $db = new PDO('mysql:dbname=books;host=127.0.0.1','root','123456');
    $data[':username']=$_POST['username'];
    $data[':password']=$_POST['password'];
    $search = $db->prepare('select * from admin where username=:username and password=:password');
    $search->execute($data);
    if($search->fetch()){
        echo "<script> alert('登录成功!'); location.href='../index.php';</script>";
    }else{
        echo "<script> alert('登录失败!'); location.href='../html/login.php';</script>";
    }

} catch (PDOException $e) {
    echo 'Connection failed';
}
?>

</body>
</html>